package io.renren.modules.app.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import io.renren.modules.app.dao.ArticleDao;
import io.renren.modules.app.entity.ArticleEntity;
import io.renren.modules.app.service.ArticleService;
import org.springframework.stereotype.Service;

import java.util.Map;


@Service("articleService")
public class ArticleServiceImpl extends ServiceImpl<ArticleDao, ArticleEntity> implements ArticleService {

    @Override
    public PageUtils queryPage(Map<String, Object> params, Integer type, String keyword) {
        QueryWrapper<ArticleEntity> queryWrapper = new QueryWrapper<>();
        if (type != null && type != -1) {
            queryWrapper.eq("fenlei_type", type);
        }

        if (keyword != null && keyword.length() != 0) {
            queryWrapper.eq("keywords", keyword);
        }

        IPage<ArticleEntity> page = this.page(
                new Query<ArticleEntity>().getPage(params), queryWrapper
        );

        return new PageUtils(page);
    }
    @Override
    public PageUtils queryIndexPage(Map<String, Object> params, Integer type) {
        QueryWrapper<ArticleEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("fenlei_type", type);
        queryWrapper.eq("show_index",1);

        IPage<ArticleEntity> page = this.page(
                new Query<ArticleEntity>().getPage(params), queryWrapper
        );

        return new PageUtils(page);
    }
}
